package com.huidu.bitrade.dao;

import com.huidu.bitrade.dao.base.BaseDao;
import com.huidu.bitrade.entity.OtcBusinessRealization;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.math.BigDecimal;
import java.util.List;

public interface OtcBusinessRealizationDao extends BaseDao<OtcBusinessRealization> {
    @Query(value = "select IFNULL(sum(amount),0) from otc_business_realization where member_id = :memberId and status =:status and create_time >= CURDATE()",nativeQuery = true)
    BigDecimal findTodayAmount(@Param("memberId") Long memberId, @Param("status")Integer status);

    @Query(value = "select IFNULL(sum(a.amount),0) from otc_business_realization a where a.create_time between :startTime and :endTime and a.member_id=:memberId",nativeQuery = true)
    BigDecimal getDayRealization(@Param("startTime") String startTime,@Param("endTime")String endTime,@Param("memberId")Long memberId);

    @Query(value = "select a.* from otc_business_realization a where a.member_id=:memberId and status in (0,2)",nativeQuery = true)
    List<OtcBusinessRealization> findByMemberIdAndStatus(@Param("memberId") Long memberId);

    @Query(value = "select IFNULL(sum(a.amount),0) from otc_business_realization a where a.member_id=:memberId and status=1",nativeQuery = true)
    BigDecimal getAllGain(@Param("memberId") Long memberId);

}
